{template 'public/header'}
<link rel="stylesheet" type="text/css" href="../addons/yzzc_sun/template/public/ygcss.css">
<style type="text/css">
    input[type="radio"] + label::before {
        content: "\a0"; /*不换行空格*/
        display: inline-block;
        vertical-align: middle;
        font-size: 16px;
        width: 1em;
        height: 1em;
        margin-right: .4em;
        border-radius: 50%;
        border: 2px solid #ddd;
        text-indent: .15em;
        line-height: 1;
    }

    input[type="radio"]:checked + label::before {
        background-color: #444444;
        background-clip: content-box;
        padding: .1em;
        border: 2px solid #444444;
    }

    input[type="radio"] {
        position: absolute;
        clip: rect(0, 0, 0, 0);
    }

    .ismap .maps {
        height: 380px;
        width: 550px;
        overflow: hidden;
        border: 1px solid #E4E4E4;
    }
</style>

<ul class="nav nav-tabs">
    <span class="ygxian"></span>
    <div class="ygdangq">当前位置:</div>
    <li class="active"><a href="javascript:void(0);">商家列表</a></li>
</ul>

<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <!--<input type="hidden" name="parentid" value="{$parent['id']}" />-->
        <div class="panel panel-default ygdefault">
            <div class="panel-heading wyheader">
                商家设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店所属地区</label>
                    <div class="col-sm-10">
                        {if $info['store_id'] >0}
                        <select name="province" id="province">
                            <!--<option value="{$item['province']}">{$item['province_name']}</option>-->
                            <option value="0">请选择省</option>
                            {loop $province $pro}
                            {if $info['province']==$pro['code']}
                            <option value="{$pro['code']}" selected="selected">{$pro['fullname']}</option>
                            {else}
                            <option value="{$pro['code']}">{$pro['fullname']}</option>
                            {/if}
                            {/loop}
                        </select>
                        <select name="city" id="city" >
                            <option value="{$info['city']}">{$info['city_name']}</option>
                        </select>
                        <select name="area" id="area" >
                            <option value="{$info['area']}">{$info['area_name']}</option>
                        </select>
                        {else}
                        <select name="province" id="province">
                            <option value="0">请选择省</option>
                            {loop $province $pro}
                            <option value="{$pro['code']}">{$pro['fullname']}</option>
                            {/loop}
                        </select>
                        <select name="city" id="city" style="display: none">

                        </select>
                        <select name="area" id="area" style="display: none" >

                        </select>
                        {/if}
                        <div class="help-block">*直辖市，如北京市、天津市、重庆市、上海市，第一项请先选择别的，再选择“请选择省”</div>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">详细地址</label>
                    <div class="col-sm-4">
                        <input type="text" name="address" value="{$info['address']}" placeholder="输入详细地址，如：杏林湾营运中心9号楼"
                               autocomplete="off" id="address" class="form-control">
                        <a href="javascript:;" class="layui-btn layui-btn-normal floatleft" id="selectshop"
                           onClick="codeAddress();">定位</a>
                        <div class="ismap">
                            <div class="maps" id="dituContent"></div>
                            <br/>
                            <p class="red">输入完整地址后，点击定位获得商户的经纬度（如定位不准，可手动拖动定位）</p>
                            <br/>
                            <p>当前经纬度：
                                <input class="hrefto jing layui-input" readonly="readonly" style="display: inline-block;"
                                       type="text" name="lng" value="{$info['lng']}"/>
                                <input class="hrefto wei layui-input" readonly="readonly" type="text"
                                       style="display: inline-block;" name="lat" value="{$info['lat']}"/></p>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="lastn" class="col-sm-2 control-label">是否送车上门</label>
                    <div class="col-sm-10">
                        <label class="radio-inline">
                            <input onchange="check(this)" type="radio" id="emailwy" name="sm" value="0" {if $info['ranges']==0}checked{/if} />
                            <label for="emailwy">关闭</label>
                        </label>
                        <label class="radio-inline">
                            <input onchange="check(this)" type="radio" id="emailwy3" name="sm" value="1" {if $info['ranges']>0}checked{/if} />
                            <label for="emailwy3">开启</label>
                        </label>
                        <div class="help-block">*是否送车上门，关闭则不提供送车上门</div>
                    </div>
                </div>
                <div class="form-group" id="range" style="display: none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">送车上门范围</label>
                    <div class="col-sm-4">
                        <p class="input-group" style="margin-bottom: 0px;">
                            <input type="number" name="ranges" value="{$info['ranges']}" class="form-control"
                                   style="width: 390px;"/>
                        </p>
                        <div class="help-block">*请输送车上门范围，单位：km</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店名称</label>
                    <div class="col-sm-4">
                        <p class="input-group" style="margin-bottom: 0px;">
                            <input type="text" name="name" value="{$info['name']}" class="form-control"/>
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">营业时间</label>
                    <div class="col-sm-4">
                        <p class="input-group" style="margin-bottom: 0px;">
                            <input type="text" name="business_hours" value="{$info['business_hours']}"
                                   class="form-control" style="width: 390px;"/>
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">服务热线</label>
                    <div class="col-sm-4">
                        <p class="input-group" style="margin-bottom: 0px;">
                            <input type="number" name="service_tel" value="{$info['service_tel']}" class="form-control"
                                   style="width: 390px;"/>
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店电话</label>
                    <div class="col-sm-4">
                        <p class="input-group" style="margin-bottom: 0px;">
                            <input type="number" name="shop_tel" value="{$info['shop_tel']}" class="form-control"
                                   style="width: 390px;"/>
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店图片</label>
                    <div class="col-sm-9">
                        {php echo tpl_form_field_image('pic', $info['pic']);}
                        <span class="help-block">*建议比例 335*185</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">营业执照</label>
                    <div class="col-sm-9">
                        {php echo tpl_form_field_image('driving_license', $info['driving_license']);}
                        <span class="help-block">*建议比例 335*185</span>
                    </div>
                </div>

            </div>
        </div>

        <div class="form-group">
<!--            <input type="submit" name="submit" value="提交" class="btn col-lg-3"-->
<!--                   style="color: white;background-color: #444444;margin-left: 550px;"/>-->
            <input type="hidden" name="token" value="{$_W['token']}"/>
            <input type="hidden" name="store_id" value="{$info['store_id']}"/>
        </div>
    </form>
</div>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&libraries=place&key={$map_key}"></script>
<script type="text/javascript">
    $(function () {
        $("#frame-1").show();
        $("#yframe-1").addClass("wyactive");
    })
    function check() {
        var a= $('input[name="sm"]:checked').val()
        if(a==1){
            $('#range') .show();
        }else{
            $('#range') .hide();
        }
    }

    function checkSm() {
        var a= $('input[name="sm"]:checked').val()
        if(a==1){
            $('#range') .show();
        }else{
            $('#range') .hide();
        }
    }
    function findname() {
        var uid=$('input[name="uid"]').val();
        $.ajax({
            type:"post",
            url:"{php echo $this->createWebUrl('addbranchadmin',array('op'=>'findname'))}",
            dataType:"json",
            data:{uid:uid},
            success:function(data){
                console.log(data);
                if(data){
                    $('#username').html('请确认用户昵称为：'+data.user_name);
                }else{
                    $('#username').html('当前用户不存在');
                }

            }
        })
    }

    var flag = 0;
    $("#province").change(function(){
        flag = 0;
        var  code=$(this).val();
        $.ajax({
            type:"POST",
            url:"{php echo $this->createWebUrl('branch',array('op'=>'getcity'))}",
            dataType:"JSON",
            data:{code: code},
            success:function(res){
                $("#city").show();
                var data = res;
                var html='';
                $.each(data, function(i, item){
                    html += '<option value="'+item.code+'">'+item.fullname+'</option>'
                })
                $('#city').html(html);
                if(flag == 0) {
                    changes(data[0].code);
                }
            },
        })
    });
    function changes (code){
        flag = 1;
        $.ajax({
            type:"POST",
            url:"{php echo $this->createWebUrl('branch',array('op'=>'getcity'))}",
            dataType:"JSON",
            data:{code: code},
            success:function(res){
                $("#area").show();
                var data = res;
                var html='';
                $.each(data, function(i, item){
                    var selected = '';
                    var area = "{$info['area']}";
                    if (area == item.code){
                        selected = 'selected'
                    }
                    html += '<option value="'+item.code+'" '+selected+'>'+item.fullname+'</option>'
                })
                $('#area').html(html);
            },
            fail: function (res) {
                console.log(11111);
            }
        })
    }
    $("#city").change(function(){
        var  code=$(this).val();
        $.ajax({
            type:"POST",
            url:"{php echo $this->createWebUrl('branch',array('op'=>'getcity'))}",
            dataType:"JSON",
            data:{code: code},
            success:function(res){
                $("#area").show();
                var data = res;
                var html='';
                $.each(data, function(i, item){
                    html += '<option value="'+item.code+'">'+item.fullname+'</option>'
                })
                $('#area').html(html);
            },
            fail: function (res) {
                console.log(11111);
            }
        })
    });
    getCity();
    function getCity(){
        var code = "{$info['province']}"
        $.ajax({
            type:"POST",
            url:"{php echo $this->createWebUrl('branch',array('op'=>'getcity'))}",
            dataType:"JSON",
            data:{code: code},
            success:function(res){
                $("#city").show();
                var data = res;
                var html='';
                $.each(data, function(i, item){
                    var selected = '';
                    var city = "{$info['city']}";
                    if (city == item.code){
                        selected = 'selected'
                    }
                    html += '<option value="'+item.code+'" '+selected+'>'+item.fullname+'</option>'
                })
                $('#city').html(html);
                if(flag == 0) {
                    changes(data[0].code);
                }
            },
        })
    }
</script>
<script>
    var namestr = "{$info['address']}"
    var lng = "{$info['lng']}";
    var lat = "{$info['lat']}";
    $(function () {
        if (namestr != null && namestr != '') {
            var center = new qq.maps.LatLng(lat, lng);

            var map = new qq.maps.Map(document.getElementById('dituContent'), {
                center: center,
                zoom: 13
            });
            var marker = new qq.maps.Marker({
                position: center,
                draggable: true,
                map: map
            });

            geocoder = new qq.maps.Geocoder({
                complete: function (result) {
                    // $('input[name=address]').val(result.detail.address);
                    map.setCenter(result.detail.location);
                    marker.setPosition(result.detail.location);
                    var weizhi1 = marker.getPosition();
                    $('input[name=lat]').val(weizhi1.lat);
                    $('input[name=lng]').val(weizhi1.lng);
                }

            });
            var ap = new qq.maps.place.Autocomplete(document.getElementById('address'));
            //调用Poi检索类。用于进行本地检索、周边检索等服务。
            var searchService = new qq.maps.SearchService({
                map: map
            });
            //添加监听事件
            qq.maps.event.addListener(ap, "confirm", function (res) {

                geocoder.getLocation(res.value);
                //若服务请求失败，则运行以下函数
                geocoder.setError(function () {
                    alert("出错了，请输入正确的地址！！！");
                });
            });

            qq.maps.event.addListener(marker, 'dragend', function (event) {
                var latLng = event.latLng,
                    lat = latLng.getLat(),
                    lng = latLng.getLng();

                // var coord = new qq.maps.LatLng(lat,lng);
                // geocoder.getAddress(coord);
                $('input[name=lat]').val(lat);
                $('input[name=lng]').val(lng);
            });
        } else {
            //				console.log(5);
            //				$(".ismap").show();
            //				    var center = new qq.maps.LatLng(39.916527,116.397128);
            //				    map = new qq.maps.Map(document.getElementById('dituContent'),{
            //				        center: center,
            //				        zoom: 13
            //				    });
            //				    //获取城市列表接口设置中心点
            //				    citylocation = new qq.maps.CityService({
            //				        complete : function(result){
            //				            map.setCenter(result.detail.latLng);
            //				             if (marker != null) {
            //				                marker.setMap(null);
            //				            }
            //				            //设置marker标记
            //				            marker = new qq.maps.Marker({
            //				                map: map,
            //				                position: results.detail.latLng
            //				            });
            //				        }
            //				    });
            ////				    var marker = new qq.maps.Marker({
            ////				        position: center,
            ////				        map: map
            ////				    });
            //				    //调用searchLocalCity();方法    根据用户IP查询城市信息。
            //				    citylocation.searchLocalCity();
        }

    })
    //清除地图上的marker
    //		function clearOverlays(overlays) {
    //			var overlay;
    //			while(overlay = overlays.pop()) {
    //				overlay.setMap(null);
    //			}
    //		}
    function codeAddress() {
        var address = document.getElementById("address").value;
        var namestr = "{$item['address']}"
        // alert(address);
        //通过getLocation();方法获取位置信息值
        if (namestr != null && namestr != '') {
            geocoder.getLocation(address);

        } else {
            var center = new qq.maps.LatLng(39.916527, 116.397128);
            var map = new qq.maps.Map(document.getElementById('dituContent'), {
                center: center,
                zoom: 13
            });

            function replaceLikeVal(comp) {
                if (comp.value.indexOf("'") != -1 || comp.value.indexOf("\"") != -1) {
                    //comp.value = comp.value.substring(0, comp.value.length-1);
                    comp.value = comp.value.replace(/\'/g, "").replace(/\"/g, "");
                }
            };
            var searchService, markers = [];
            //设置Poi检索服务，用于本地检索、周边检索
            searchService = new qq.maps.SearchService({
                //检索成功的回调函数
                complete: function (results) {

                    //设置回调函数参数
                    var pois = results.detail.pois;

                    if (!pois) {
                        //						alert('请输入详细的地址(xxx市xxx县xxx镇xxx)');
                        alert("请输入详细的地址");
                    }
                    var infoWin = new qq.maps.InfoWindow({
                        map: map
                    });
                    var latlngBounds = new qq.maps.LatLngBounds();
                    for (var i = 0, l = pois.length; i < l; i++) {
                        var poi = pois[i];
                        //扩展边界范围，用来包含搜索到的Poi点
                        latlngBounds.extend(poi.latLng);

                        (function (n) {
                            var marker = new qq.maps.Marker({
                                position: center,
                                draggable: true,
                                map: map
                            });

                            marker.setPosition(pois[n].latLng);

                            marker.setTitle(i + 1);
                            markers.push(marker);
                            $('.wei').val(pois[n].latLng.lat);
                            $('.jing').val(pois[n].latLng.lng);
                            qq.maps.event.addListener(marker, 'dragend', function (event) {
                                var latLng = event.latLng,
                                    lat = latLng.getLat(),
                                    lng = latLng.getLng();

                                // var coord = new qq.maps.LatLng(lat,lng);
                                // geocoder.getAddress(coord);
                                $('.jing').val(lng);
                                $('.wei').val(lat);
                            });
                        })(i);
                    }
                    //调整地图视野
                    map.fitBounds(latlngBounds);
                },
                //若服务请求失败，则运行以下函数
                error: function () {
                    alert('请输入有效地址')
                }
            });
            $(".map").show();
            var keyword = document.getElementById("address").value;
            console.log(keyword);
            var region = '';
            var pageIndex = 0;
            var pageCapacity = 1;
            //			clearOverlays(markers);
            //根据输入的城市设置搜索范围
            searchService.setLocation(region);
            //设置搜索页码
            searchService.setPageIndex(pageIndex);
            //设置每页的结果数
            searchService.setPageCapacity(pageCapacity);
            //根据输入的关键字在搜索范围内检索
            searchService.search(keyword);
            //根据输入的关键字在圆形范围内检索
            //var region = new qq.maps.LatLng(39.916527,116.397128);
            //searchService.searchNearBy(keyword, region , 2000);
            //根据输入的关键字在矩形范围内检索
            //region = new qq.maps.LatLngBounds(new qq.maps.LatLng(39.936273,116.440043),new qq.maps.LatLng(39.896775,116.354212));
            //searchService.searchInBounds(keyword, region);

        }
    }

    //		function replaceLikeVal(comp) {
    //			if(comp.value.indexOf("'") != -1 || comp.value.indexOf("\"") != -1) {
    //				//comp.value = comp.value.substring(0, comp.value.length-1);
    //				comp.value = comp.value.replace(/\'/g, "").replace(/\"/g, "");
    //			}
    //		};
    //		var searchService, markers = [];
    //		var init = function() {
    //			var center = new qq.maps.LatLng(39.916527, 116.397128);
    //			var map = new qq.maps.Map(document.getElementById('dituContent'), {
    //				center: center,
    //				zoom: 13
    //			});
    //
    //			//设置Poi检索服务，用于本地检索、周边检索
    //			searchService = new qq.maps.SearchService({
    //				//检索成功的回调函数
    //				complete: function(results) {
    //
    //					//设置回调函数参数
    //					var pois = results.detail.pois;
    //
    //					if(!pois) {
    ////						alert('请输入详细的地址(xxx市xxx县xxx镇xxx)');
    //						layer.msg("请输入详细的地址(xxx市xxx县xxx镇xxx)", {
    //							icon: 2,
    //							time: 1000
    //						});
    //						return false;
    //					}
    //					var infoWin = new qq.maps.InfoWindow({
    //						map: map
    //					});
    //					var latlngBounds = new qq.maps.LatLngBounds();
    //					for(var i = 0, l = pois.length; i < l; i++) {
    //						var poi = pois[i];
    //						//扩展边界范围，用来包含搜索到的Poi点
    //						latlngBounds.extend(poi.latLng);
    //
    //						(function(n) {
    //							var marker = new qq.maps.Marker({
    //								position: center,
    //								draggable: true,
    //								map: map
    //							});
    //
    //							marker.setPosition(pois[n].latLng);
    //
    //							marker.setTitle(i + 1);
    //							markers.push(marker);
    //							$('.wei').val(pois[n].latLng.lat);
    //							$('.jing').val(pois[n].latLng.lng);
    //
    //							// qq.maps.event.addListener(marker, 'click', function() {
    //							//     infoWin.open();
    //							//     infoWin.setContent('<div style="width:280px;height:100px;">' + 'POI的ID为：' +
    //							//         pois[n].id + '，POI的名称为：' + pois[n].name + '，POI的地址为：' + pois[n].address + '，POI的类型为：' + pois[n].type + '</div>');
    //							//     infoWin.setPosition(pois[n].latLng);
    //							// });
    //							qq.maps.event.addListener(marker, 'dragend', function(event) {
    //								var latLng = event.latLng,
    //									lat = latLng.getLat(),
    //									lng = latLng.getLng();
    //
    //								// var coord = new qq.maps.LatLng(lat,lng);
    //								// geocoder.getAddress(coord);
    //								$('.jing').val(lng);
    //								$('.wei').val(lat);
    //							});
    //						})(i);
    //					}
    //					//调整地图视野
    //					map.fitBounds(latlngBounds);
    //				},
    //				//若服务请求失败，则运行以下函数
    //				error: function() {
    ////					alert("出错了。");
    //				layer.msg("您还没填地址呢", {
    //					icon: 2,
    //					time: 1000
    //				});
    //				}
    //			});
    //
    //		}
    //
    //		//清除地图上的marker
    //		function clearOverlays(overlays) {
    //			var overlay;
    //			while(overlay = overlays.pop()) {
    //				overlay.setMap(null);
    //			}
    //		}
    //		//设置搜索的范围和关键字等属性
    //		function searchKeyword() {
    //			$(".map").show();
    //			var keyword = document.getElementById("address").value;
    //			console.log(keyword);
    //			var region = '';
    //			var pageIndex = 0;
    //			var pageCapacity = 1;
    //			clearOverlays(markers);
    //			//根据输入的城市设置搜索范围
    //			searchService.setLocation(region);
    //			//设置搜索页码
    //			searchService.setPageIndex(pageIndex);
    //			//设置每页的结果数
    //			searchService.setPageCapacity(pageCapacity);
    //			//根据输入的关键字在搜索范围内检索
    //			searchService.search(keyword);
    //			//根据输入的关键字在圆形范围内检索
    //			//var region = new qq.maps.LatLng(39.916527,116.397128);
    //			//searchService.searchNearBy(keyword, region , 2000);
    //			//根据输入的关键字在矩形范围内检索
    //			//region = new qq.maps.LatLngBounds(new qq.maps.LatLng(39.936273,116.440043),new qq.maps.LatLng(39.896775,116.354212));
    //			//searchService.searchInBounds(keyword, region);
    //
    //		}
</script>